import { HttpClient, ServerRouteHttpClient } from "@/axios/HttpClient";
import APIConst from "@/common/constants/APIConst";
import { APIResponse } from "@/common/model/APIResponse";
import { store, storeCommitPath } from "@/store/index";
import { AxiosResponse } from "axios";

const SysMsgService = {
  async getSysMsgTable(compCode: string, userid: string) {
    const reqObj = {};
    let Response: AxiosResponse;
    if (!store.state.baseUrl) {
      //First time login
      Response = await ServerRouteHttpClient.post<APIResponse>(
        APIConst.localization.messages(compCode, userid),
        reqObj
      );
    } else {
      Response = await HttpClient.post<APIResponse>(
        APIConst.localization.messages(compCode, userid),
        reqObj
      );
    }
    const data = Response.data.Data;
    // store.commit(storeCommitPath.setSysMsg, data);
  },
  getSysMsg(langConst: any) {
    const SysMsg: any = store.state.sysMsg;
    if (SysMsg) {
      const Msg = SysMsg.find(
        (x: any) =>
          x.FieldType == langConst.FieldType &&
          x.FieldName == langConst.FieldName
      );
      if (Msg) {
        return Msg.MsgString;
      } else {
        return langConst.FieldName;
      }
    } else {
      return langConst.FieldName;
    }
  },
};
export default SysMsgService;
